#import <Flutter/Flutter.h>
#import "OupayCCBPay.h"
#import <CCBNetPaySDK/CCBNetPaySDK.h>
#import "NSString+MD5.h"

@implementation OupayCCBPay





+ (void) startPay: (NSString*)payInfo result:(FlutterResult)result
{
     //先MD5
      NSString * digest = [payInfo MD5Digest];
    //2 和MAC拼起来
      NSString * MAC =[@"&MAC=" stringByAppendingString:digest];
    //3 和前面的字符串拼起来
      payInfo =[payInfo stringByAppendingString:MAC];
    //4 调用方法
    [[CCBNetPay defaultService] payOrder:payInfo callback:^(NSDictionary * dic){
        NSString * isSuccess = [dic objectForKey:@"SUCCESS"];
        NSMutableDictionary * resultDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                                @"",@"pay_result",nil];
        //赋值Y是成功
        [resultDict setValue:isSuccess forKey:@"pay_result"];
        //返回结果
        result(resultDict);
      
    }];
    
}


//回调通知
+ (BOOL)handleOpenURL:(NSURL*)url result:(FlutterResult)result
{
//    [[UPPaymentControl defaultControl] handlePaymentResult:url completeBlock:^(NSString *code, NSDictionary *data) {
//        NSMutableDictionary * resultDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
//                                            @"",@"pay_result",
//                                            @"",@"data",
//                                            @"",@"sign",nil];
//        [resultDict setValue:code forKey:@"pay_result"];
//
//        if([code isEqualToString:@"success"]) {
//            //结果code为成功时，去商户后台查询一下确保交易是成功的再展示成功
//            if(data != nil){
//                [resultDict addEntriesFromDictionary:data];
//            }
//        }
//
//        result(resultDict);
//
//    }];
    
    return YES;
}


@end
